from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base:
    def __init__(self):
        #设备能力集
        cap={
  "platformName": "Android",
  "deviceName": "emulator-5554",
  "automationName": "uiautomator2",
  "appPackage": "com.kongfz.app",
  "appActivity": ".home.mvvm.homepage.HomeActivity",
  "noReset": False
}
        #远程连接设备
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.driver.implicitly_wait(20)
        #元素定位
    def find_dingwei(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待定位元素
    def find_xianshi(self,loc):
        ele=WebDriverWait(self.driver,10).until((EC.element_to_be_clickable(*loc)))
        return ele
    #滑动
    def find_hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,200)
    #轻触
    def find_qingchu(self,a,b):
        self.driver.tap([(a,b)],200)
    #截图
    def find_jietu(self,loc):
        self.driver.save_screenshot(loc)
    #退出
    def find_tuichu(self):
        self.driver.quit()
    #大反
    def find_fanhui(self):
        self.driver.press_keycode(3)
    #长按
    def find_chagnan(self,loc):
        ele=self.driver.find_element(*loc)
        action=TouchAction(self.driver)
        action.long_press(el=ele,duration=2000).release().perform()
    #拖拽
    def find_tuozhuai(self,k,j):
        action=TouchAction(self.driver)
        action.press(k[0],k[1]).wait(2000).move_to(j[0],j[1]).release().perform()
    #获取元素值
    def find_huoquyuansu(self,loc):
        ele=self.driver.find_element(*loc)
        t=ele.text
        return print(t)




